package com.bioroadlab.dao;

import net.sf.json.JSONObject;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.bioroadlab.pojo.Disease;
import com.bioroadlab.pojo.DiseaseType;

@Repository
public class DiseaseTypeDao extends BaseDao<DiseaseType, Integer> {

	public DiseaseType findByDisease(Disease disease) {
		String hql = "from DiseaseType where sn=:sn";
		Query query = getSession().createQuery(hql);
		query.setParameter("sn", disease.getDiseaseType().getSn());
		DiseaseType dt = (DiseaseType) query.uniqueResult();
		return dt;
	}

	public JSONObject findDiseaseTypeJsonBy(Disease disease) {
		String hql = "from DiseaseType a inner join fetch a.diseaseCategory b where a.sn=:sn";

		Query query = getSession().createQuery(hql);
		query.setParameter("sn", disease.getDiseaseType().getSn());
		DiseaseType dt = (DiseaseType) query.uniqueResult();
		JSONObject json = JSONObject.fromObject(dt);

		return json;
	}

	public void update(DiseaseType diseaseType) {
		getSession().update(diseaseType);
	}

}
